package cn.iocoder.yudao.module.system.service.examscore;

import cn.iocoder.yudao.module.system.controller.admin.examscore.vo.NewExamScoreImportExcelVO;
import cn.iocoder.yudao.module.system.controller.admin.examscore.vo.ExamScoreImportRespVO;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 新高考成绩导入服务接口
 * 支持新高考改革的完整数据结构，包括选科组合、赋分制度、多维度排名等
 *
 * @author 芋道源码
 */
public interface NewExamScoreImportService {

    /**
     * 批量导入新高考成绩
     * 支持自动创建班级、学生、选科组合等
     *
     * @param file Excel文件
     * @return 导入结果
     * @throws IOException IO异常
     */
    ExamScoreImportRespVO importNewExamScores(MultipartFile file) throws IOException;

    /**
     * 批量导入新高考成绩（指定考试）
     *
     * @param examId 考试ID
     * @param file Excel文件
     * @return 导入结果
     * @throws IOException IO异常
     */
    ExamScoreImportRespVO importNewExamScores(Long examId, MultipartFile file) throws IOException;

    /**
     * 解析Excel文件标题，提取考试信息
     *
     * @param file Excel文件
     * @return 考试信息
     * @throws IOException IO异常
     */
    ExamInfoFromTitle parseExamInfoFromTitle(MultipartFile file) throws IOException;

    /**
     * 获取新高考成绩导入模板
     *
     * @return 模板数据
     */
    List<NewExamScoreImportExcelVO> getNewImportTemplate();

    /**
     * 验证导入数据的完整性
     *
     * @param importData 导入数据列表
     * @return 验证结果
     */
    ImportDataValidationResult validateImportData(List<NewExamScoreImportExcelVO> importData);

    /**
     * 自动创建班级
     *
     * @param className 班级名称
     * @param grade 年级
     * @return 班级ID
     */
    Long autoCreateClass(String className, String grade);

    /**
     * 自动创建学生并分配到班级
     *
     * @param studentData 学生数据
     * @param classId 班级ID
     * @return 学生ID
     */
    Long autoCreateStudent(NewExamScoreImportExcelVO studentData, Long classId);

    /**
     * 自动识别和创建选科组合
     *
     * @param combinationCode 组合编码
     * @return 选科组合信息
     */
    SubjectCombinationInfo autoCreateSubjectCombination(String combinationCode);

    /**
     * 计算赋分
     *
     * @param subjectName 科目名称
     * @param originalScore 原始分
     * @param allScores 所有学生该科目的原始分列表
     * @return 赋分结果
     */
    ScoreAssignmentResult calculateAssignedScore(String subjectName, Double originalScore, List<Double> allScores);

    /**
     * 计算多维度排名
     *
     * @param examId 考试ID
     */
    void calculateMultiDimensionalRanking(Long examId);

    /**
     * 保存科目成绩详情
     *
     * @param examId 考试ID
     * @param studentId 学生ID
     * @param importData 导入数据
     */
    void saveSubjectScoreDetails(Long examId, Long studentId, NewExamScoreImportExcelVO importData);

    /**
     * 保存最高分记录
     *
     * @param examId 考试ID
     * @param studentId 学生ID
     * @param importData 导入数据
     */
    void saveTopScoreRecord(Long examId, Long studentId, NewExamScoreImportExcelVO importData);

    /**
     * 从Excel标题解析的考试信息
     */
    class ExamInfoFromTitle {
        private String examName;
        private String examType;
        private String gradeLevel;
        private String semester;
        private String subjectDirection;
        private String examCategory;
        
        // 构造函数、getter、setter
        public ExamInfoFromTitle() {}
        
        public ExamInfoFromTitle(String examName, String examType, String gradeLevel, 
                               String semester, String subjectDirection, String examCategory) {
            this.examName = examName;
            this.examType = examType;
            this.gradeLevel = gradeLevel;
            this.semester = semester;
            this.subjectDirection = subjectDirection;
            this.examCategory = examCategory;
        }
        
        // Getters and Setters
        public String getExamName() { return examName; }
        public void setExamName(String examName) { this.examName = examName; }
        
        public String getExamType() { return examType; }
        public void setExamType(String examType) { this.examType = examType; }
        
        public String getGradeLevel() { return gradeLevel; }
        public void setGradeLevel(String gradeLevel) { this.gradeLevel = gradeLevel; }
        
        public String getSemester() { return semester; }
        public void setSemester(String semester) { this.semester = semester; }
        
        public String getSubjectDirection() { return subjectDirection; }
        public void setSubjectDirection(String subjectDirection) { this.subjectDirection = subjectDirection; }
        
        public String getExamCategory() { return examCategory; }
        public void setExamCategory(String examCategory) { this.examCategory = examCategory; }
    }

    /**
     * 导入数据验证结果
     */
    class ImportDataValidationResult {
        private boolean valid;
        private List<String> errorMessages;
        private List<String> warningMessages;
        private int totalCount;
        private int validCount;
        
        // 构造函数、getter、setter
        public ImportDataValidationResult() {}
        
        public ImportDataValidationResult(boolean valid, List<String> errorMessages, 
                                        List<String> warningMessages, int totalCount, int validCount) {
            this.valid = valid;
            this.errorMessages = errorMessages;
            this.warningMessages = warningMessages;
            this.totalCount = totalCount;
            this.validCount = validCount;
        }
        
        // Getters and Setters
        public boolean isValid() { return valid; }
        public void setValid(boolean valid) { this.valid = valid; }
        
        public List<String> getErrorMessages() { return errorMessages; }
        public void setErrorMessages(List<String> errorMessages) { this.errorMessages = errorMessages; }
        
        public List<String> getWarningMessages() { return warningMessages; }
        public void setWarningMessages(List<String> warningMessages) { this.warningMessages = warningMessages; }
        
        public int getTotalCount() { return totalCount; }
        public void setTotalCount(int totalCount) { this.totalCount = totalCount; }
        
        public int getValidCount() { return validCount; }
        public void setValidCount(int validCount) { this.validCount = validCount; }
    }

    /**
     * 选科组合信息
     */
    class SubjectCombinationInfo {
        private Long id;
        private String combinationCode;
        private String combinationName;
        private List<String> subjects;
        private String category;
        
        // 构造函数、getter、setter
        public SubjectCombinationInfo() {}
        
        public SubjectCombinationInfo(Long id, String combinationCode, String combinationName, 
                                    List<String> subjects, String category) {
            this.id = id;
            this.combinationCode = combinationCode;
            this.combinationName = combinationName;
            this.subjects = subjects;
            this.category = category;
        }
        
        // Getters and Setters
        public Long getId() { return id; }
        public void setId(Long id) { this.id = id; }
        
        public String getCombinationCode() { return combinationCode; }
        public void setCombinationCode(String combinationCode) { this.combinationCode = combinationCode; }
        
        public String getCombinationName() { return combinationName; }
        public void setCombinationName(String combinationName) { this.combinationName = combinationName; }
        
        public List<String> getSubjects() { return subjects; }
        public void setSubjects(List<String> subjects) { this.subjects = subjects; }
        
        public String getCategory() { return category; }
        public void setCategory(String category) { this.category = category; }
    }

    /**
     * 赋分结果
     */
    class ScoreAssignmentResult {
        private Double assignedScore;
        private String gradeLevel;
        private Double percentage;
        private String description;
        
        // 构造函数、getter、setter
        public ScoreAssignmentResult() {}
        
        public ScoreAssignmentResult(Double assignedScore, String gradeLevel, 
                                   Double percentage, String description) {
            this.assignedScore = assignedScore;
            this.gradeLevel = gradeLevel;
            this.percentage = percentage;
            this.description = description;
        }
        
        // Getters and Setters
        public Double getAssignedScore() { return assignedScore; }
        public void setAssignedScore(Double assignedScore) { this.assignedScore = assignedScore; }
        
        public String getGradeLevel() { return gradeLevel; }
        public void setGradeLevel(String gradeLevel) { this.gradeLevel = gradeLevel; }
        
        public Double getPercentage() { return percentage; }
        public void setPercentage(Double percentage) { this.percentage = percentage; }
        
        public String getDescription() { return description; }
        public void setDescription(String description) { this.description = description; }
    }
}